//引入菜单的接口方法
import { memberlist, allMembercount } from "../../request/api";

export default {
    state: {
        memberList: [],//这是member的初始数组
        is: {//判断是否显示dialog 弹窗
            show: false
        },
        total: 0, //这是页码总数
        pageNum: 1,//这是页码数
        pageSize: 4,//这是条数
    },
    getters: {},
    mutations: {
        //修改member数据 初始数据
        REQ_MEMBER(state, payload) {
            state.memberList = payload;
        },

        //修改dialog弹窗
        changeDialog(state, payload) {
            state.is.show = payload;
        },

        //修改总数
        changeTotal(state, payload) {
            state.total = payload;
        },

        //修改page页码数
        changePage(state, payload) {
            state.pageNum = payload;
        }
    },
    actions: {
        //异步操作 获取数据 member
        getMember(context) {
            memberlist({ page: context.state.pageNum, size: context.state.pageSize }).then(res => {
                //第一次 修改数据 渲染页面
                context.commit("REQ_MEMBER", res.list);
            });

        },

        //获取总条数
        getMemberTotal(context) {
            //获取总条数的接口
            allMembercount().then(res => {
                //传给 mutations  修改数据
                context.commit('changeTotal', res.list[0].total);
            })
        },

        //切换分页 获取数据
        getPage(context, payload) {
            //切换分页
            context.commit('changePage', payload);
            //切换分页之后 要重新获取数据
            context.dispatch('getMember');
        }
    },
    namespaced: true
}